package com.hzqy.service.weather;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.commons.utils.JsonUtils;
import com.hzqy.persistence.dao.picture.PictureDao;
import com.hzqy.persistence.dao.weather.WeatherDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.CmPicturesVo;
import com.hzqy.web.vo.WeatherCommonVo;

@Service
public class WeatherServiceBean extends GenericServiceBean<WeatherCommonVo, WeatherDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private WeatherDao weatherDao;
	@Override
	public WeatherDao getEntityDao() {
		return weatherDao;
	}
	
	
	/**
	 * 根据id查询天气详情
	 * @param F_wfc_id
	 * @return
	 */
	public WeatherCommonVo selectWeatherCommonVo(String f_wfc_id) {
		return weatherDao.selectWeatherCommonVo(f_wfc_id);
	}
	
	/**
	 * 	天气列表获取
	 * @param WeatherCommonVo
	 * @param curPage
	 * @param pageSize
	 * @return
	 */
	public Map<String,Object> selectWeatherCommonList(WeatherCommonVo weatherCommonVo, int curPage,
			int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = weatherDao.selectWeatherCommonCount(weatherCommonVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_wfc_date", weatherCommonVo.getF_wfc_date());
			map.put("f_wfc_areaname", weatherCommonVo.getF_wfc_areaname());
			map.put("f_wfc_source", weatherCommonVo.getF_wfc_source());
			map.put("startTime", weatherCommonVo.getStartTime());
			map.put("endTime", weatherCommonVo.getEndTime());
			List<WeatherCommonVo> results = weatherDao.selectWeatherCommonList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<WeatherCommonVo>());
		}
		return map;
	}
	

	/**
	 * 删除天气
	 * @param f_wfc_id
	 * @return
	 */
	public int deleteWeatherCommonVo(String f_wfc_id) {
		weatherDao.deleteWeatherCommonVo(f_wfc_id);
		return 1;
	}
	/**
	 * 增加天气
	 * @param weatherVo
	 * @return
	 */
	public Map<String,Object> insertWeatherCommonVo(WeatherCommonVo weatherVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(weatherVo==null || weatherVo.getF_wfc_areaname()==null) {
			flag = -1;
		}
		if(weatherVo.getF_wfc_weather()!=null) {
			weatherVo.setF_wfc_daytime_weather(weatherVo.getF_wfc_weather());
		}
		if(flag ==0) {
				int f_wfc_id =weatherDao.insertWeatherCommonVo(weatherVo);
				resultMap.put("success", true);
				resultMap.put("result","新增天气成功!");
				resultMap.put("f_wfc_id",f_wfc_id);
		}else{
			resultMap.put("success", false);
			resultMap.put("result","新增天气失败!");
		}
		return resultMap;
	}
	/**
	 * 修改天气
	 * @param weatherVo
	 * @return
	 */
	public Map<String,Object> updateWeather(WeatherCommonVo weatherVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(weatherVo==null || weatherVo.getF_wfc_areaname()==null) {
			flag = -1;
		}
		if(flag ==0) {
			weatherDao.updateWeatherCommonVo(weatherVo);
			resultMap.put("success", true);
			resultMap.put("result","修改天气成功!");
		}else{
			resultMap.put("success", false);
			resultMap.put("result","修改天气失败!");
		}
		return resultMap;
	}
}
